<template>
  <div class="box">  
    <p style="font-size: 30px;font-weight: 700;">分中心学生客户公海策略设置</p>
    <div style="text-align: left; margin-top: 2%">
      <el-row>
        <el-col :span="24">
            <p style=" font-size: 24px; 1%; font-weight: 700; ">总部分配客户:</p>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="7">
           <span style=" font-size: 20px;  font-weight: 700; ">是否自动回归公海</span>
        </el-col>
        <el-col :span="17">
          <el-radio-group v-model="radio">
            <el-radio label="1">是</el-radio>
            <el-radio label="2">否</el-radio>
          </el-radio-group>
        </el-col>
      </el-row>
    </div>
    <div class="input-box">
      <el-row style="margin-top:2%">
        <el-col :span="6">
          <span class="tit" style="">自动回归期限：</span>
        </el-col>
        <el-col :span="16">
        <el-row >
          <el-col :span="24">
            <el-col :span="15">
              <el-row>
                <el-col :span="12">
                  <el-row>
                    <el-col :span="10">
                      <span style="margin-top:10%;display: inline-block;">未跟进：</span>
                    </el-col>
                    <el-col :span="14">
                      <el-input v-model="deletedIds"></el-input>
                    </el-col>
                  </el-row>
                </el-col>
              </el-row>
              <el-row style="margin-top:5%">
                <el-col :span="12">
                  <el-row>
                    <el-col :span="10">
                      <span style="margin-top:10%;display: inline-block;">未成单：</span>
                    </el-col>
                    <el-col :span="14">
                      <el-input v-model="single_shard"></el-input>
                    </el-col>
                  </el-row>
                </el-col>
              </el-row>
              </el-col>
          </el-col>
        </el-row>
        </el-col>
      </el-row>      
    </div>
    <div class="clear"></div>
     <div style="text-align: left; margin-top: 2%">
      <el-row>
        <el-col :span="24">
          <p style=" font-size: 24px; font-weight: 700;">OEM卡激活客户:</p>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="7">
           <span style=" font-size: 20px;  font-weight: 700; ">是否自动回归公海</span>
        </el-col>
        <el-col :span="17">
          <el-radio-group v-model="OEM">
            <el-radio label="1">是</el-radio>
            <el-radio label="2">否</el-radio>
          </el-radio-group>
        </el-col>
      </el-row>
    </div>
     <div class="input-box">
      <el-row style="margin-top:2%">
        <el-col :span="6">
          <span class="tit" style="">自动回归期限：</span>
        </el-col>
        <el-col :span="16">
        <el-row >
          <el-col :span="24">
            <el-col :span="15">
              <el-row>
                <el-col :span="12">
                  <el-row>
                    <el-col :span="10">
                      <span style="margin-top:10%;display: inline-block;">未跟进：</span>
                    </el-col>
                    <el-col :span="14">
                      <el-input v-model="OEMdeletedIds"></el-input>
                    </el-col>
                  </el-row>
                </el-col>
              </el-row>
              <el-row style="margin-top:5%">
                <el-col :span="12">
                  <el-row>
                    <el-col :span="10">
                      <span style="margin-top:10%;display: inline-block;">未成单：</span>
                    </el-col>
                    <el-col :span="14">
                      <el-input v-model="OEMsingle_shard"></el-input>
                    </el-col>
                  </el-row>
                </el-col>
              </el-row>
              </el-col>
          </el-col>
        </el-row>
        </el-col>
      </el-row>
    </div>
    <div class="clear"></div>
    <div style="margin-top: 2%;">
      <KtButton
        :label="$t('action.close')"
        perms='true'
        type="primary"
        size="medium"
        style="margin-right: 2%;"
        @click="closeSelectedTag()"
      ></KtButton>
      <KtButton
        :label="$t('action.save')"
        perms='true'
        type="primary"
        size="medium"
        style="margin-top: 2%; "
        @click="save"
      ></KtButton>
    </div>
  </div>
</template>

<script>
import PersonalTable from "@/views/Core/PersonalTable";
import DepartmentTable from "@/views/Core/DepartmentTable";
import KtButton from "@/views/Core/KtButton";
export default {
  name: "school",
  components: {
    KtButton
  },
  data() {
    return {
      radio: "",
      OEM:"",
      selectedTag: this.$route.path,
      listCustomerAutomaticAssignStrategy: [],
      deletedIds: "", //未跟进
      single_shard: "",//未成单
      OEMdeletedIds: "", //未跟进
      OEMsingle_shard: "" //未成单
    };
  },
  computed: {
    visitedViews() {
      // console.log("tabView");
      // console.log(this.$store.state.tagsview);
      // console.log(this.$store.state.visitedViews);
      return this.$store.state.tagsview.visitedViews;
    }
  },
  watch: {
    visible(value) {
      if (value) {
        document.body.addEventListener("click", this.closeMenu);
      } else {
        document.body.removeEventListener("click", this.closeMenu);
      }
    }
  },
  methods: {
    getConfig() {
      // 总部分配客户
      this.$api.student
        .strategyConfigQueryConfig({
          names: "BC_AUTOWARE_RETURN_SEA_FROM_HQ",
          type: 1
        })
        .then(res => {
          this.radio = res.customerAssignConfig[0].value;
        });
         // OEM卡
      this.$api.student
        .strategyConfigQueryConfig({
          names: "BC_AUTOWARE_RETURN_SEA_FROM_OEM",
          type: 1
        })
        .then(res => {
          this.OEM = res.customerAssignConfig[0].value;
        });
      // 获取总部未跟进
      this.$api.student
        .strategyConfigQueryConfig({
          names: "BC_NOT_TRACKING_RETURN_SEA_CYCLE_FROM_HQ",
          type: 1
        })
        .then(res => {
          this.deletedIds = res.customerAssignConfig[0].value;
        });
      // 获取总部未成单
      this.$api.student
        .strategyConfigQueryConfig({
          names: "BC_NOT_SIGN_RETURN_SEA_CYCLE_FROM_HQ",
          type: 1
        })
        .then(res => {
          this.single_shard = res.customerAssignConfig[0].value;
        });
        // 获取OEM未跟进
      this.$api.student
        .strategyConfigQueryConfig({
          names: "BC_NOT_TRACKING_RETURN_SEA_CYCLE_FROM_OEM",
          type: 1
        })
        .then(res => {
          this.OEMdeletedIds = res.customerAssignConfig[0].value;
        });
      // 获取OEM未成单
      this.$api.student
        .strategyConfigQueryConfig({
          names: "BC_NOT_SIGN_RETURN_SEA_CYCLE_FROM_OEM",
          type: 1
        })
        .then(res => {
          this.OEMsingle_shard = res.customerAssignConfig[0].value;
        });
    },
    //  保存
    save() {
      let aa=[]
      let bb = [];
      let customerAssignConfigList2 = Object.assign({}, this.radio);
      let customerAssignConfigList = Object.assign({}, this.OEM);
      aa.push(customerAssignConfigList)
      bb.push(customerAssignConfigList2);
      aa.forEach(item => {
        item.value = item[0];
        item.name = "BC_AUTOWARE_RETURN_SEA_FROM_OEM";
      });
      bb.forEach(item => {
        item.value = item[0];
        item.name = "BC_AUTOWARE_RETURN_SEA_FROM_HQ";
      });
      this.$api.student
        .strategyConfigSetConfig({
          customerAssignConfigList: aa,
          type: 1
        })
        .then(res => {
          if (res.result == 2) {
            this.$message({
              message: res.msg,
              type: "error"
            });
          } else {
            this.$message({
              message: res.msg,
              type: "success"
            });
          }
        });
      this.$api.student
        .strategyConfigSetConfig({
          customerAssignConfigList: bb,
          type: 1
        })
        .then(res => {
          if (res.result == 2) {
            this.$message({
              message: res.msg,
              type: "error"
            });
          } else {
            this.$message({
              message: res.msg,
              type: "success"
            });
          }
        });
      // 设置未跟进：
      let customerAssignConfigListA = [
        {
          name: "BC_NOT_TRACKING_RETURN_SEA_CYCLE_FROM_HQ",
          value: this.deletedIds
        }
      ];
      this.$api.student
        .strategyConfigSetConfig({
          customerAssignConfigList: customerAssignConfigListA,
          type: 1
        })
        .then(res => {
          if (res.result == 2) {
            this.$message({
              message: res.msg,
              type: "error"
            });
          } else {
            this.$message({
              message: res.msg,
              type: "success"
            });
          }
        });
      // 设置未成单：
      let customerAssignConfigListB= [
        {
          name: "BC_NOT_SIGN_RETURN_SEA_CYCLE_FROM_HQ",
          value: this.single_shard
        }
      ];
      this.$api.student
        .strategyConfigSetConfig({
          customerAssignConfigList: customerAssignConfigListB,
          type: 1
        })
        .then(res => {
          if (res.result == 2) {
            this.$message({
              message: res.msg,
              type: "error"
            });
          } else {
            this.$message({
              message: res.msg,
              type: "success"
            });
          }
        });
      // 设置OEM未跟进：
      let customerAssignConfigListC = [
        {
          name: "BC_NOT_TRACKING_RETURN_SEA_CYCLE_FROM_OEM",
          value: this.OEMdeletedIds
        } 
      ];
      this.$api.student
        .strategyConfigSetConfig({
          customerAssignConfigList: customerAssignConfigListC,
          type: 1
        })
        .then(res => {
          if (res.result == 2) {
            this.$message({
              message: res.msg,
              type: "error"
            });
          } else {
            this.$message({
              message: res.msg,
              type: "success"
            });
          }
        });
      // 设置oem未成单：
      let customerAssignConfigListD= [
        {
          name: "BC_NOT_SIGN_RETURN_SEA_CYCLE_FROM_OEM",
          value: this.OEMsingle_shard
        }
      ];
      this.$api.student
        .strategyConfigSetConfig({
          customerAssignConfigList: customerAssignConfigListD,
          type: 1
        })
        .then(res => {
          if (res.result == 2) {
            this.$message({
              message: res.msg,
              type: "error"
            });
          } else {
            this.$message({
              message: res.msg,
              type: "success"
            });
          }
        });
    },
    generateRoute() {
      if (this.$route.name) {
        return this.$route;
      }
      return false;
    },
    isActive(route) {
      return route.path === this.$route.path;
    },
    closeSelectedTag(view) {
      this.$store.dispatch("delVisitedViews", this.$route).then(views => {
        if (this.isActive(this.$route)) {
          const latestView = views.slice(-1)[0];
          if (latestView) {
            this.$router.push(latestView);
          } else {
            this.$router.push("/");
          }
        }
      });
    }
  },
  mounted() {
    this.getConfig();
  }
};
</script>

<style lang="scss">
.el-table {
  display: block;
}
.has-gutter tr th {
  text-align: center;
}
.el-table__row td > .cell {
  text-align: center;
}
</style>
<style lang="scss" scoped>
.box{
  margin-left: 3%!important;
}
.input-box {
  margin-top: 2%;
  margin:0 auto;
  .tit{
    display:inline-block;
    font-size: 20px; 
    font-weight: 700;
  }
  .input-box-c .el-row{
    margin-top:10%;
  }
}
.container .el-radio-group .el-radio:first-child{
  display: inline-block;
}
.el-row .el-col{
  margin-left: 0;
}
</style>


